﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MipsPipelineSimulator
{
    class RunTimeCode
    {
        static private List<Code> codeList = new List<Code>();

        static private int codeStartAddress = 0;

        static public void Add(Code code)
        {
            codeList.Add(code);
        }

        static public void Add(Code[] codes)
        {
            codeList.AddRange(codes);
        }

        static public int CodeStartAddress
        {
            set
            {
                codeStartAddress = value;
            }
            get
            {
                return codeStartAddress;
            }
        }

        static public Code GetCode(int codeCurrentAddress)
        {
            int index = (codeCurrentAddress - CodeStartAddress)/4;
            if (index < 0 || index >= codeList.Count)
            {
                Code code = new Code();
                code.codeType = CodeType.Over;
                return code;
            }
            return codeList[index];
        }

        static void Clear()
        {
            codeList.Clear();
        }
    }
}
